package media

import (
	"server/common"

	"github.com/mitchellh/mapstructure"
)

// -------------------------------------------------------------------------------------------------
//
// -------------------------------------------------------------------------------------------------
func (s *MediaService) handleRegisterServiceRes(msg common.Message) {
	common.Logger(common.SERVICE_TYPE_MEDIA).WithField("msg", common.ToJson(msg)).
		Info("handling register service response")

	if msg.Data == nil {
		LOG(msg.Rid).Error("register service response data is nil")
		return
	}

	var resData common.ResMsgData
	if err := mapstructure.Decode(msg.Data, &resData); err != nil {
		LOG(msg.Rid).WithError(err).Error("failed to decode register service response data")
		return
	}

	if resData.Code != 0 {
		LOG(msg.Rid).Errorf("service registration failed: %s", resData.Msg)
		return
	}

	common.Logger(common.SERVICE_TYPE_MEDIA).Info("service registered successfully")
}
